<template>
  <div class="app" :data-theme="theme" :class="{ 'is-overlay': isOverlay }">
    <div class="main-container" v-if="!isOverlay">
      <h1 class="app-title">Focus Tide - 专注潮汐</h1>
      <Timer />
    </div>
    <TideAnimation v-else />
  </div>
</template>

<script setup>
import { ref, onMounted } from 'vue';
import { getCurrentWindow } from '@tauri-apps/api/window';
import Timer from './components/Timer.vue';
import TideAnimation from './components/TideAnimation.vue';

const theme = ref('light');
const isOverlay = ref(false);

onMounted(async () => {
  console.log('App mounted');
  
  // 检查是否为覆盖窗口
  try {
    const appWindow = getCurrentWindow();
    if (appWindow.label === 'overlay') {
      isOverlay.value = true;
      document.body.style.background = 'transparent';
    }
  } catch (e) {
    console.error('Failed to get current window:', e);
  }

  // 检测系统主题
  const prefersDark = window.matchMedia('(prefers-color-scheme: dark)');
  theme.value = prefersDark.matches ? 'dark' : 'light';
  
  prefersDark.addEventListener('change', (e) => {
    theme.value = e.matches ? 'dark' : 'light';
  });
});
</script>

<style>
:root {
  /* 浅色主题 */
  --color-primary: #3B82F6;
  --color-primary-dark: #2563EB;
  --color-bg: #FFFFFF;
  --color-bg-secondary: #F9FAFB;
  --color-bg-hover: #F3F4F6;
  --color-text: #111827;
  --color-text-secondary: #6B7280;
  --color-border: #E5E7EB;
  --color-danger: #EF4444;
}

[data-theme="dark"] {
  /* 深色主题 */
  --color-primary: #60A5FA;
  --color-primary-dark: #3B82F6;
  --color-bg: #1F2937;
  --color-bg-secondary: #374151;
  --color-bg-hover: #4B5563;
  --color-text: #F9FAFB;
  --color-text-secondary: #9CA3AF;
  --color-border: #4B5563;
  --color-danger: #F87171;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
    'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
    sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  background: var(--color-bg);
  color: var(--color-text);
}

.app {
  height: 100vh;
  width: 100%;
  background: var(--color-bg);
  transition: background-color 0.3s, color 0.3s;
  overflow: hidden; /* 防止出现滚动条 */
}

.app.is-overlay {
  background: transparent;
}

.main-container {
  height: 100%;
  display: flex;
  flex-direction: column;
  background: var(--color-bg);
}

.app-title {
  margin: 0;
  padding: 1.5rem 0;
  text-align: center;
  color: var(--color-text-secondary);
  font-size: 0.9rem;
  font-weight: 400;
  letter-spacing: 3px;
  text-transform: uppercase;
  flex-shrink: 0;
  opacity: 0.8;
}
</style>
